<? require("adm_header.php");

writeCommonAdminTable(LA_ADMIN_STAT,1);
  

$resultat = mysql_query ("select count(*) from $ads_tbl");
$rad = mysql_fetch_array($resultat);
$ads_total = $rad["count(*)"];

$resultat = mysql_query ("select count(*) from $usr_tbl");
$rad = mysql_fetch_array($resultat);
$usr_total = $rad["count(*)"];

$resultat = mysql_query ("select count(*) from $pic_tbl");
$rad = mysql_fetch_array($resultat);
$pic_total = $rad["count(*)"];

$resultat = mysql_query ("select count(*) from $cat_tbl");
$rad = mysql_fetch_array($resultat);
$cat_total = $rad["count(*)"];

$resultat = mysql_query ("select count(*) from $template_tbl");
$rad = mysql_fetch_array($resultat);
$temp_total = $rad["count(*)"];

print "<table width='50%' class='noBorder'>";
print "<tr><td>".LA_ADMIN_STAT_ADS.":</td><td>$ads_total</td></tr>";
print "<tr><td>".LA_ADMIN_STAT_USERS.":</td><td>$usr_total</td></tr>";
print "<tr><td>".LA_ADMIN_STAT_PICTURES.":</td><td>$pic_total</td></tr>";
print "<tr><td>".LA_ADMIN_STAT_CATS.":</td><td>$cat_total</td></tr>";
print "<tr><td>".LA_ADMIN_STAT_TPL.":</td><td>$temp_total</td></tr>";
print "</table>";
	
$array[1]="Janary";
$array[2]="February";
$array[3]="March";
$array[4]="April";
$array[5]="May";
$array[6]="June";
$array[7]="July";
$array[8]="August";
$array[9]="September";
$array[10]="October";
$array[11]="November";
$array[12]="December";

echo "<h3>".LA_ADMIN_STAT_ADSSTAT."</h3>";
$sql_total="select count(*) as total_ads_last_12 from $ads_tbl order by ad_date limit 12";
$row=mysql_fetch_array(q($sql_total));
$lTotal = $row["total_ads_last_12"];
echo "<table width='600'>";
$sql="select count(*) as num_ads_month, YEAR(FROM_UNIXTIME(ad_date)) as yr, MONTH(FROM_UNIXTIME(ad_date)) as mo from $ads_tbl group by yr,mo order by ad_date desc";
$res=q($sql);
$lYearTotal=0;
$this_was_year="";
while ($row=mysql_fetch_array($res))
{
		$lNumAdsThisMonth=$row["num_ads_month"];
		$lYear=$row["yr"];
		$lMonth=$row["mo"];
		if ($this_was_year<>$lYear)
		{
			echo "<tr><td colspan='2'><br /><b>$lYear</b></td></tr>";
			$lReset=1;
		}
		$lYearTotal+=$lNumAdsThisMonth;
		$lLength=round(($lNumAdsThisMonth/$lTotal)*100);
		$lLength_bar=$lLength*3;
		echo "<tr><td width='35%'><b>".$array[$lMonth]."</b> ($lNumAdsThisMonth ads)</td>";
		echo "<td width='65%'><img src='graph.gif' align='left' height='5' width='$lLength_bar%' alt='$lLength% of all ads last 12 months' /></td></tr>";
		
		if ($lReset==1)
		{
			
			echo "<tr><td colspan='2'><hr>$lYearTotal ".LA_ADMIN_STAT_INTOTAL."<br /><br /></td></tr>";
			
			$lYearTotal=0;
			$lReset=0;
		}
		
		
		
		$this_was_year=$lYear;
}
echo "</table>";

$this_was_year="";
echo "<p>&nbsp;</p><h3>".LA_ADMIN_STAT_NEWUSERS."</h3>";
$sql_total="select count(*) as total_users_joined from $usr_tbl order by user_date limit 12";
$row=mysql_fetch_array(q($sql_total));
$lTotal = $row["total_users_joined"];
echo "<table width='600'>";
$sql="select count(user_id) as num_users_month, YEAR(FROM_UNIXTIME(user_date)) as yr, MONTH(FROM_UNIXTIME(user_date)) as mo from $usr_tbl group by yr,mo order by user_date desc";
$res=q($sql);
while ($row=mysql_fetch_array($res))
{
		$lNumAdsThisMonth=$row["num_users_month"];
		$lYear=$row["yr"];
		$lMonth=$row["mo"];
		if ($this_was_year<>$lYear)
			echo "<tr><td colspan='2'><br /><b>$lYear</b><hr></td></tr>";
		$lLength=round(($lNumAdsThisMonth/$lTotal)*100);
		$lLength_bar=$lLength*3;
		echo "<tr><td width='35%'><b>".$array[$lMonth]."</b> ($lNumAdsThisMonth users, $lLength%)</td>";
		echo "<td width='65%'><img src='graph.gif' align='left' height='5' width='$lLength_bar%' alt='$lLength% of all users joined last 12 months' /></td></tr>";
		$this_was_year=$lYear;
}
echo "</table>";


$this_was_year="";
echo "<p>&nbsp;</p><h3>".LA_ADMIN_STAT_LOGINS."</h3>";
$sql_total="select count(*) as total_users_joined from $usr_tbl order by user_date_last_login  limit 12";
$row=mysql_fetch_array(q($sql_total));
$lTotal = $row["total_users_joined"];
echo "<table width='600'>";
$sql="select count(user_id) as num_users_month, YEAR(FROM_UNIXTIME(user_date_last_login)) as yr, MONTH(FROM_UNIXTIME(user_date_last_login)) as mo from $usr_tbl group by yr,mo order by user_date_last_login desc";
$res=q($sql);
while ($row=mysql_fetch_array($res))
{
		$lNumAdsThisMonth=$row["num_users_month"];
		$lYear=$row["yr"];
		$lMonth=$row["mo"];
		if (round($lYear)>2000)
		{
		if ($this_was_year<>$lYear)
			echo "<tr><td colspan='2'><br /><b>$lYear</b><hr></td></tr>";
		$lLength=round(($lNumAdsThisMonth/$lTotal)*100);
		$lLength_bar=$lLength*3;
		echo "<tr><td width='35%'><b>".$array[$lMonth]."</b> ($lNumAdsThisMonth users, $lLength%)</td>";
		echo "<td width='65%'><img src='../layout_images/graph.gif' align='left' height='5' width='$lLength_bar%' alt='$lLength% of all users logged in last 12 months logged in in " . $array[$lMonth] . "' /></td></tr>";
		$this_was_year=$lYear;
		}
	
}
echo "</table>";


?>


<?writeCommonAdminTable("Statistics","");?>


<? require("adm_footer.php"); ?>
